local fenrui = fk.CreateSkill {
  name = "tyj_heg__fenrui",
}
local H = require "packages.ol_hegemony.util"
local U = require "packages.utility.utility"
Fk:loadTranslationTable {
  ["tyj_heg__fenrui"] = "奋锐",
  [":tyj_heg__fenrui"] = "出牌阶段限一次，你可以重铸一张装备牌以亮出牌堆顶的牌直到亮出【杀】，然后你获得此【杀】并可以使用一张以此法亮出的牌（不计入次数）。",
  ["#tyj_heg__fenrui"] = "奋锐：你可以重铸一张装备牌，从牌堆顶翻找一张【杀】并使用翻出的一张牌。",
  ["$tyj_heg__fenrui1"] = "善守者亦善攻，不可死守。",
  ["$tyj_heg__fenrui2"] = "璋军疲敝，可伺机而攻。",
  ["~tyj_heg__huojun"] = "蒙君知遇，奈何早薨。",
}
fenrui:addEffect("active", {
  anim_type = "offensive",
  card_num = 1,
  target_num = 0,
  prompt = "#tyj_heg__fenrui",
  times = function(self, player)
    return player.phase == Player.Play and 1 - player:usedSkillTimes(fenrui.name, Player.HistoryPhase) or -1
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(fenrui.name, Player.HistoryPhase) == 0 and not player:isNude()
  end,
  card_filter = function(self, player, to_select, selected)
    local card = Fk:getCardById(to_select)
    return #selected == 0 and card.type == Card.TypeEquip     --and not Self:prohibitDiscard(to_select)
  end,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local from = effect.from
    if from:isAlive() then
      --room:throwCard(effect.cards, self.name, from, from)
      room:recastCard(effect.cards, from)
      if from:isAlive() then
        local card
        local cards = {}
        local cardstouse = {}
        while true do
          if from:isAlive() then
            local id = room:getNCards(1)[1]
            room:moveCardTo(id, Card.Processing, nil, fk.ReasonJustMove, fenrui.name, nil, true, from.id)
            table.insert(cardstouse, id)
            room:delay(300)
            local c = Fk:getCardById(id)
            if c.trueName == "slash" then
              card = c
              room:delay(500)
              break
            else
              table.insert(cards, id)
            end
          else
            break
          end
        end
        if from:isAlive() and room:getCardOwner(card.id) == nil then
          room:moveCardTo(card.id, Player.Hand, from, fk.ReasonPrey, fenrui.name, nil, true, from.id)
        end
        if from:isAlive() and #cardstouse > 0 then
          room:askToUseRealCard(from, {
            pattern = cardstouse,
            skill_name = fenrui.name,
            prompt = "奋锐：你可以使用亮出的一张牌",
            extra_data = {
              expand_pile = table.filter(cardstouse,
                function(cid) return room:getCardOwner(cid) ~= from and room:getCardArea(cid) ~= Card.PlayerHand end),
              extra_use = true
            }
          })
        end
        cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
        room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, fenrui.name, nil, true, from.id)
      end
    end
  end,
})
return fenrui
